package com.lorenzogao.customview

import android.animation.ObjectAnimator
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.lorenzogao.customviewexample.R
import com.lorenzogao.lib_view.ColorTrackTextView
import kotlinx.android.synthetic.main.activity_color_track.*
import kotlinx.android.synthetic.main.layout_head.*

class ColorTrackActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_color_track)

        setToolBar(toolbar, "玩转字体变色")


        btn_left.setOnClickListener { leftToRight() }

        btn_right.setOnClickListener { rightToLeft() }


    }

    private fun leftToRight(){
        tvColorTrack.setDirection(ColorTrackTextView.DIRECTION.LEFT_TO_RIGHT)
        val objectAnimator=ObjectAnimator.ofFloat(0f,1f)
        objectAnimator.duration=2000
        objectAnimator.addUpdateListener {
            tvColorTrack.setCurrentProgress(it.animatedValue as Float)
        }

        objectAnimator.start()
    }



    private fun rightToLeft(){
        tvColorTrack.setDirection(ColorTrackTextView.DIRECTION.RIGHT_TO_LEFT)
        val objectAnimator=ObjectAnimator.ofFloat(0f,1f)
        objectAnimator.duration=2000
        objectAnimator.addUpdateListener {
            tvColorTrack.setCurrentProgress(it.animatedValue as Float)
        }

        objectAnimator.start()
    }
}
